#include<iostream>
#include<vector>
using namespace std;
const int N=1010;
int main(){
  int n,m,q;
  cin>>n>>m>>q;
  int a[N][N];
  auto b=a;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++)cin>>a[i][j];
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++) 
      b[i][j]=a[i][j]+b[i-1][j]+b[i][j-1]-b[i-1][j-1];
  }
  while(q--){
    int y1,x1,y2,x2;
    cin>>y1>>x1>>y2>>x2;
    cout<<b[y2][x2]-b[y2][x1-1]-b[y1-1][x2]+b[y1-1][x1-1]<<endl;
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++)  cout<<b[i][j]<<" ";
    cout<<endl;
  }
}